﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text ,RichText } from '@tarojs/components'
import qunimg from '../../assets/images/A6984900727459logo.png'
import CommonJs from '../../utils/common'
import './chat.scss' 
export default class ChatList extends Component {
	constructor(props) {
    super(props);
    this.state = {
      yybf: 0,
      yyts: 0,
    }
  }
  opendetails(url,id,type,shopId,freeGoOrderId){
    if (type == 1) {
      this.$preload('activityId',id)
    } else if (type == 2) {
      this.$preload('commodityId',id)
    } else if (type == 3) {
		 
      this.$preload({
        'commodityId':id,
        'shopId':shopId,
        'freeGoOrderId':freeGoOrderId
      })
    }
    CommonJs.openTo(url);
  }
  openxq(id){
  	this.$preload({
	  	mid:'',
	  	couponid:id,
	  	byfrom:''
	})
  	this.open("/pages/coupon/details");
  }
  open(url,type){
    CommonJs.openTo(url)
  }
  lookbigimg(data){
    this.props.onHandleImg(data);
  }
  buzhichi(){
    Taro.showModal({
      title: '提示',
      content: '抱歉，小程序不允许你访问网页链接，如需获得最全功能和更好体验请下载“蝌蚪社区”APP!',
      showCancel: false
    })
  }
  bofangyy(url){
    let _this = this
    let yyts = _this.state.yyts
    
    if (yyts == 0) {
        _this.setState({
            yyts: 1
        })
        const innerAudioContext = Taro.createInnerAudioContext()
        innerAudioContext.src = url
        innerAudioContext.play()
        innerAudioContext.onPlay(() => {
          _this.setState({
            yybf: 1
          })
        })
        innerAudioContext.onEnded((res) => {
	
          _this.setState({
            yybf: 0,
            yyts: 0
          })
        })
    }
  }
  
  render () {
    const item = this.props.propItem;
    const userid = Taro.getStorageSync('dateinfo').userid;
    const red = this.state.info
    console.log(JSON.stringify(item)+'1111111')
    let RichTexts = null;
    let contents = item.content;
    let index = contents.indexOf("|||");//是否包含
    let bosh = null;
    let markUrl = null;
    let markUrls = [];
    let sendObjectId = item.sendObjectId;
    if(sendObjectId == 11){//群管后台活动列表分享活动 
      markUrl = item.markUrl;
    }
    if(markUrl){//群管后台活动列表分享活动 
      markUrls = markUrl.split("|||");
      
    }
    if(index >= 0){
      bosh = contents.split("|||");
    }
    if (markUrls[0] == 1012 && markUrls[1] == "project") {
      RichTexts = (
        <RichText className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} nodes={bosh[2]} onClick={this.opendetails.bind(this,'/pages/activitydetails/activitydetails',markUrls[2],1)}></RichText>
      )
    } else if (index < 0) {
      RichTexts = (
        <RichText className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} nodes={contents}></RichText>
      )
    } else if (bosh[1] == "pic") {
      RichTexts = (
        <View className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} style='max-width:50%;'>
          <Image className='lotn-img' mode='widthFix' src={bosh[0]} onClick={this.lookbigimg.bind(this,bosh[0])}></Image>
        </View>
      )
    } else if (bosh[1] == "ActivityShare") {
      RichTexts = (
        <View className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} onClick={this.opendetails.bind(this,'/pages/activitydetails/activitydetails',bosh[5],1)}>
          <View className='qun-hodng'>
            <View className='qun-tities'>{bosh[2]}</View>
            <View className='qun-infos'>
              <View className='qun-infoleft'>{bosh[4]}</View>
              <View className='qun-inforight'><Image className='qun-houdoimgs' mode='widthFix' src={bosh[3]}></Image></View>
            </View>
          </View>
        </View>
      )
    } else if (bosh[1] == "pkgShare") {
      RichTexts = (
        <View className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} onClick={this.buzhichi.bind(this)}>
          <View className='qun-hodng'>
            <View className='qun-tities'>{bosh[2]}</View>
            <View className='qun-infos'>
              <View className='qun-infoleft'>{bosh[4]}</View>
              <View className='qun-inforight'><Image className='qun-houdoimgs' mode='widthFix' src={bosh[3]}></Image></View>
            </View>
          </View>
        </View>
      )
    } else if(bosh[1] == "yuyin") {
      RichTexts = (
        <View className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} onClick={this.bofangyy.bind(this,bosh[0])}>
          {item.id == userid ?
            <View className='qun-syuyinz'>
              <View className='qun-yuyinmao'>{bosh[2]}s</View>
              <Image className='qun-yuyinzimg' mode='' src={this.state.yybf == 0 ? 'https://minichat.g2ma.com/kedouimg/yy.png' : 'https://minichat.g2ma.com/kedouimg/yy01.gif'}></Image>
            </View>
            :
            <View className='qun-syuyinz'>
              <Image className='qun-yuyinzimg' mode='' src={this.state.yybf == 0 ? 'https://minichat.g2ma.com/kedouimg/yy.png' : 'https://minichat.g2ma.com/kedouimg/yy01.gif'}></Image>
              <View className='qun-yuyinmao'>{bosh[2]}s</View>
            </View>
          }
        </View>
      )
    } else if(bosh[1] == "freegouShare") {
      RichTexts = (
        <View className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} onClick={this.opendetails.bind(this,'/pages/pkgo/pkgodetails',bosh[5],3,bosh[6],bosh[7])}>
          <View className='qun-hodng'>
            <View className='qun-tities'>{bosh[2]}</View>
            <View className='qun-infos'>
              <View className='qun-infoleft'>{bosh[4]}</View>
              <View className='qun-inforight'><Image className='qun-houdoimgs' mode='widthFix' src={bosh[3]}></Image></View>
            </View>
          </View>
        </View>
      )
    } 
    else if(bosh[1] == "yhq"){
    	RichTexts = (
        	<View className='yhq-dl' onClick={this.openxq.bind(this,bosh[0])}>
    				<View className="yhq-dt">
    						<View style={bosh[3].indexOf('DISCOUNT')>=0?'':'display:none'}>
    						<Text className="jg">{bosh[2]/10}</Text>
    						<Text className="tb"> 折</Text>
    						</View>
    						<View style={bosh[3].indexOf('DISCOUNT')>=0?'display:none':''}>
    						<Text className="tb">¥</Text>
    						<Text className="jg">{bosh[2]/100}</Text>
    						</View>
    						<Text className="tj">{bosh[4]}</Text>
    				</View>
    				<View className="yhq-dd">
    					<Text className="yhq-sy">立即领取</Text>
    				</View>
    		</View>
      	)
    }
    else {
      RichTexts = (
        <RichText className={item.id==userid?'chatting-words chatmysend':'chatting-words chatfriendsend'} nodes={contents}></RichText>
      )
    }
    return (
      <View className='qun-lotn'>
        {RichTexts}
      </View>
    )
  }
}